<?php

declare(strict_types=1);

namespace app\core\Task;
use Swoole\Coroutine\Client;

class Request{

    public static function tcp(mixed $data,array $set=[]){
        $client = new Client(SWOOLE_SOCK_TCP);
        if (!$client->connect('127.0.0.1', 8877, 0.5))
        {
            throw new Exception("connect failed. Error: {$client->errCode}", 500);
        }
        $client->send("$data\n");
        $recv=$client->recv();
        $client->close();
        return $recv;
    }
}